import {
  birdNamesQuery,
  birdGeneral,
  birdCount
  } from 'api/birdsMonitoring';
import React from "react";

  export default {
      namespace: 'birdsMonitor',
      state: {
        birdNames: [{code:1,name:"黑鹳"},
          {code:2,name:"东方白鹤"},
          {code:14,name:"黄嘴白鹭"}],
        birdGeneral: {
          bird_type_cnt: 95,
          bird_cnt: 1185
        },
        birdCount: {
          birdTypeNames: [],
          birdCnt: []
        }
      },

      effects: {
        *birdNamesQuery({ payload }, { call, put }) {
          const result = yield call(birdNamesQuery, payload)
          if (result && result.success) {
            yield put({
              type: 'setState',
              payload: {
                birdNames: result.data,
              },
            })
          } else {
            throw data
          }
        },
        *birdGeneral({ payload }, { call, put }) {
          const result = yield call(birdGeneral, payload)
          if (result && result.success) {
            yield put({
              type: 'setState',
              payload: {
                birdGeneral: result.data,
              },
            })
          } else {
            throw data
          }
        },
        *birdCount({ payload }, { call, put }) {
          const result = yield call(birdCount, payload)
          return result;
          // if (result && result.success) {
          //   yield put({
          //     type: 'setState',
          //     payload: {
          //       birdCount: result.data,
          //     },
          //   })
          // } else {
          //   throw data
          // }
        },
      },

      reducers: {
        setState(state, action) {
          return {
              ...state,
              ...action.payload
          };
        }
      },
    }
